#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include <bitset>

using namespace std;

class Solution {
public:
    int similarPairs(vector<string>& words) {
        int cnt = 0;
        vector<bitset<26>> bitMaps_;
        for (auto word : words) {
            bitset<26> s;
            for (auto t : word)
                s.set(t - 'a');
            bitMaps_.emplace_back(s);
        }
        int len = words.size();
        for (int i = 0; i < len - 1; ++i) {
            for (int j = i + 1; j < len; ++j) {
                if (bitMaps_[i] == bitMaps_[j])
                    ++cnt;
            }
        }
        return cnt;
    }
};



class Solution2 {
public:
    string frequencySort(string s) {
        string res;
        int len = s.size();
        vector<pair<char, int>> vec(26 + 26 + 10, make_pair<char, int>(0, 0));
        for (auto c : s) {
            int offset = isdigit(c) ? 52 : ('A' <= c && c <= 'Z') ? 0 : 26;
            char t = isdigit(c) ? '0' : ('A' <= c && c <= 'Z') ? 'A' : 'a';
            vec[c - t + offset].first = c;
            ++vec[c - t + offset].second;
        }
        sort(vec.begin(), vec.end(), [](const pair<char, int>& a, const pair<char, int>& b){
            return a.second > b.second;
        });
        for (auto [k, v] : vec)
            while (v--)
                res.push_back(k);
        return res;
    }
};
int main() {
    // vector<string> a {"aba","aabb","abcd","bac","aabc"};
    // Solution solu;
    // int res = solu.similarPairs(a);
    // cout << res << endl;

    Solution2 a;
    auto t = a.frequencySort("AABB");
    cout << t << endl;

    return 0;
}